let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    year:"",
    month:"",
    monthList:[1,2,3,4,5,6,7,8,9,10,11,12,"总计"],
    detail:{
      oneCount:0,
      oneBuildCount:0,
      oneIncrease:0,
      oneInvest:0,
      oneSurplusInvest:0,
      twoCount:0,
      twoBuildCount:0,
      twoIncrease:0,
      twoInvest:0,
      twoSurplusInvest:0,
      twoRatio:0,
      threeCount:0,
      threeBuildCount:0,
      threeIncrease:0,
      threeInvest:0,
      threeSurplusInvest:0,
      threeRatio:0,
      start:1
    }
  },

  //调用后台数据
  statistics:function(){
    var year = this.data.year;
    var month = this.data.month;
    var start = this.data.start;
    var params = {year:year,month:month,start:start};
    app.request('post', '/api/Project/statistics', params).then(res => {
      let detail = res.data.detail;
      this.setData({detail:detail,month:res.data.month});
  }).catch(err => console.log(err));
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.formatTime(new Date());
    this.statistics();
  },

  formatTime:function(date) {
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    var hour = date.getHours()
    var minute = date.getMinutes()
    var second = date.getSeconds()
    this.setData({year:year,month:month})
  },

  //选择年
  changeDate:function(e){
    this.setData({year:e.detail.value});
    this.statistics();
  },

  //选择月
  changeMonth:function(e){
      var month = parseInt(e.detail.value)+1;
      this.setData({month:month,start:0});
      this.statistics();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})